<html>
<head><meta charset="utf-8"><title>Allocators conflict and FFI · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html">Allocators conflict and FFI</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213472250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213472250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213472250">(Oct 15 2020 at 18:59)</a>:</h4>
<p>Hi,</p>
<p>I have trouble understanding how things work when doing FFI calls to some <code>extern "C"</code> function that may allocate memory: Rust and C will each have their allocator, likely different. On modern Linux systems, these allocators obtain memory through <code>mmap</code> and hence are each working with different chunks of the heap and won't conflict. But is this a guarantee on every platform?</p>
<p>If we imagine something similar to <code>sbrk</code>, then both allocators would be giving-out part from the same segment of the heap, and memory may very well end up being corrupted. How strong are our guarantee against this?</p>



<a name="213473466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213473466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213473466">(Oct 15 2020 at 19:08)</a>:</h4>
<p>I believe rust uses the system allocator by default</p>



<a name="213473559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213473559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213473559">(Oct 15 2020 at 19:09)</a>:</h4>
<p>so as someone building a crate (executable/shared lib), you should only have an issue if some crate in the depndency graph overrides the global allocator</p>



<a name="213473607"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213473607" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213473607">(Oct 15 2020 at 19:10)</a>:</h4>
<p>and if that custom allocator is somehow incompatible with the allocator used by C code</p>



<a name="213473911"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213473911" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213473911">(Oct 15 2020 at 19:12)</a>:</h4>
<blockquote>
<p>Binaries generated by the compiler will use alloc_jemalloc by default (where available). In this situation the compiler "controls the world" in the sense of it has power over the final link. Primarily this means that the allocator decision can be left up the compiler.</p>
</blockquote>
<p>From <a href="https://doc.rust-lang.org/1.9.0/book/custom-allocators.html">https://doc.rust-lang.org/1.9.0/book/custom-allocators.html</a> </p>
<p>So I guess there can be a problem if I'm doing a binary right ? Or is the allocator set on a per-crate basis (in which case the problem for before is even bigger).</p>



<a name="213474629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213474629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213474629">(Oct 15 2020 at 19:18)</a>:</h4>
<p>This is the 1.9.0 documentation, this has been changed since</p>



<a name="213475217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475217">(Oct 15 2020 at 19:23)</a>:</h4>
<p>You're right it is the wrong version, but I can't find any resource on how it is done now.<br>
Anyway, I think my original question is a bit orthogonal because the C library itself may have a custom allocator for example, or might be C-ABI bindings exposed by some other language for example.</p>



<a name="213475423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475423">(Oct 15 2020 at 19:24)</a>:</h4>
<p>That sounds to me like the job of the OS, to make sure it doesn't hand 2 entities the same chunk of memory</p>



<a name="213475510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475510">(Oct 15 2020 at 19:25)</a>:</h4>
<p>System allocator is default on all platforms currently, see <a href="https://doc.rust-lang.org/nightly/std/alloc/trait.GlobalAlloc.html">https://doc.rust-lang.org/nightly/std/alloc/trait.GlobalAlloc.html</a> for docs on how to change that.</p>



<a name="213475549"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475549" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475549">(Oct 15 2020 at 19:25)</a>:</h4>
<p>oh I see your point about <code>sbrk</code> hmmm interesting</p>



<a name="213475562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475562">(Oct 15 2020 at 19:25)</a>:</h4>
<p><a href="https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#jemalloc-is-removed-by-default">https://blog.rust-lang.org/2019/01/17/Rust-1.32.0.html#jemalloc-is-removed-by-default</a></p>



<a name="213475741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elichai Turkel <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475741">(Oct 15 2020 at 19:27)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> I still think this question is quite interesting regardless of that fact.<br>
it's also interesting in C only or Rust only, can something bad happen when combining multiple allocators</p>



<a name="213475799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475799">(Oct 15 2020 at 19:27)</a>:</h4>
<p>I am confused -- what question?</p>



<a name="213475921"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213475921" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213475921">(Oct 15 2020 at 19:28)</a>:</h4>
<p>Calling malloc with one allocator and free with the other (or vice versa etc) is UB.</p>



<a name="213476072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213476072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213476072">(Oct 15 2020 at 19:29)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213475921">said</a>:</p>
<blockquote>
<p>Calling malloc with one allocator and free with the other (or vice versa etc) is UB.</p>
</blockquote>
<p>But that's not what is mentioned here: I'm asking about case where simply allocating memory could be unsound.</p>



<a name="213476247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213476247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213476247">(Oct 15 2020 at 19:30)</a>:</h4>
<blockquote>
<p>If we imagine something similar to sbrk, then both allocators would be giving-out part from the same segment of the heap, and memory may very well end up being corrupted. How strong are our guarantee against this?</p>
</blockquote>
<p>I'm not sure how this matters -- each allocator should only be looking at memory it specifically allocated</p>



<a name="213476331"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213476331" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213476331">(Oct 15 2020 at 19:31)</a>:</h4>
<p>(And I also think the question is generally interesting as a programming language design problem: many languages do not use malloc at all and ship their custom allocator, I wonder how they deal with that at their FFI bounday for example.)</p>



<a name="213476446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213476446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213476446">(Oct 15 2020 at 19:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213476247">said</a>:</p>
<blockquote>
<p>I'm not sure how this matters -- each allocator should only be looking at memory it specifically allocated</p>
</blockquote>
<p>How do they "know" what memory is theirs if all they have is a beginning and end for the heap?</p>



<a name="213476571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213476571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213476571">(Oct 15 2020 at 19:33)</a>:</h4>
<p>Specific allocators may require that they are the only ones around, but I suspect that predominantly they do not assume that they only have a beginning and end.</p>



<a name="213476710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213476710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213476710">(Oct 15 2020 at 19:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213476571">said</a>:</p>
<blockquote>
<p>Specific allocators may require that they are the only ones around, but I suspect that predominantly they do not assume that they only have a beginning and end.</p>
</blockquote>
<p>I would hope so! But I am curious about the actual guarantees we have. :)</p>



<a name="213479096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213479096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213479096">(Oct 15 2020 at 19:54)</a>:</h4>
<p>From what allocator?</p>



<a name="213483753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213483753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213483753">(Oct 15 2020 at 20:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213479096">said</a>:</p>
<blockquote>
<p>From what allocator?</p>
</blockquote>
<p>I don't understand your question.</p>



<a name="213498141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213498141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213498141">(Oct 15 2020 at 22:56)</a>:</h4>
<p><span class="user-mention silent" data-user-id="354910">krtab</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213476446">said</a>:</p>
<blockquote>
<p>How do they "know" what memory is theirs if all they have is a beginning and end for the heap?</p>
</blockquote>
<p>In something like Linux or Windows, virtual memory means that allocators <em>must</em> get their memory from the OS.  None of them work by just "knowing" where the heap is.</p>
<p>Now, if you're in Ring0 things might be different, but so will so many other things that this is the least of your problems :P</p>



<a name="213525676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213525676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213525676">(Oct 16 2020 at 07:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213498141">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="354910">krtab</span> <a href="#narrow/stream/122651-general/topic/Allocators.20conflict.20and.20FFI/near/213476446">said</a>:</p>
<blockquote>
<p>How do they "know" what memory is theirs if all they have is a beginning and end for the heap?</p>
</blockquote>
<p>In something like Linux or Windows, virtual memory means that allocators <em>must</em> get their memory from the OS.  None of them work by just "knowing" where the heap is.</p>
<p>Now, if you're in Ring0 things might be different, but so will so many other things that this is the least of your problems :P</p>
</blockquote>
<p>Could you elaborate on that? Especially even in recent linux <code>sbrk</code> is still available so I'm not sure I understand the dichotomy between "virtual memory" and "just knowing where the heap is".</p>



<a name="213526937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213526937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213526937">(Oct 16 2020 at 07:32)</a>:</h4>
<p><code>sbrk</code> based allocators should still not conflict with each other as even in C they can not really assume they are the only ones calling it. So a "proper" <code>sbrk</code> based allocator would do something like following to get a new chunk/page of memory.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">start</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">sbrk</span><span class="p">(</span><span class="n">size</span><span class="p">);</span><span class="w"></span>
<span class="k">if</span><span class="p">(</span><span class="n">start</span><span class="p">.</span><span class="n">is_null</span><span class="p">())</span><span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">oom</span><span class="p">();</span><span class="w"></span>
<span class="c1">//for simplicity no free here ;-)</span>
<span class="kd">let</span><span class="w"> </span><span class="n">chunk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">slice</span>::<span class="n">from_raw_parts</span>::<span class="o">&lt;'</span><span class="nb">static</span><span class="p">,</span><span class="kt">u8</span><span class="o">&gt;</span><span class="p">(</span><span class="n">start</span><span class="p">,</span><span class="w"> </span><span class="n">size</span><span class="p">);</span><span class="w"></span>
<span class="bp">Self</span><span class="p">.</span><span class="n">add_raw_memory</span><span class="p">(</span><span class="n">chunk</span><span class="p">);</span><span class="w"></span>
</code></pre></div>

<p>Only by using <code>brk</code> or by (dangerously) somehow assuming it owns all memory up-to start would this create a conflict.</p>
<p>Or in other words only if there is some implicitly shared process global state does this lead to problems.</p>



<a name="213527004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213527004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213527004">(Oct 16 2020 at 07:33)</a>:</h4>
<p>(as far as I know)</p>



<a name="213528391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213528391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213528391">(Oct 16 2020 at 07:50)</a>:</h4>
<p><span class="user-mention" data-user-id="209646">@Philipp Korber</span> <br>
Interesting! Do you know if "they can not really assume they are the only ones calling it" is something widely accepted? Does it have a name (like "multi allocator safety" or something)?</p>



<a name="213528694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213528694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213528694">(Oct 16 2020 at 07:54)</a>:</h4>
<p>I think it's more like a best practice then any rule, like they better should not do so because other (old) C programs they statically or dynamically link against might call <code>sbrk</code> themself.</p>



<a name="213528749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213528749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213528749">(Oct 16 2020 at 07:55)</a>:</h4>
<p>Ok! Thanks a lot!</p>



<a name="213529239"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213529239" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213529239">(Oct 16 2020 at 08:01)</a>:</h4>
<p>At least for old not really maintained libraries from the University computer since corner I have run into libraries which allocate their own block of memory using <code>sbrk</code> as a "performance optimization" (supposedly, they never ran a benchmark).</p>
<p>But in the end you can't rely on a custom allocator not doing something problematic.</p>
<p>Even if they use mmap  for system allocation the are a bunch of ways to introduce processes global state.</p>



<a name="213529458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213529458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213529458">(Oct 16 2020 at 08:04)</a>:</h4>
<p>You piqued my interest, what would be such ways?</p>



<a name="213529972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213529972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Philipp Korber <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213529972">(Oct 16 2020 at 08:09)</a>:</h4>
<p>Like having two instances of the same custom allocator which both use the same global non mangled mutable variable but both assuming that they are singletons.</p>



<a name="213530093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Allocators%20conflict%20and%20FFI/near/213530093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> krtab <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Allocators.20conflict.20and.20FFI.html#213530093">(Oct 16 2020 at 08:11)</a>:</h4>
<p>I see</p>
<p>Thanks a lot for your answers!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>